package com.kangye.enterprise.frontdesk.controller;

import com.kangye.enterprise.frontdesk.entity.*;
import com.kangye.enterprise.frontdesk.service.BannerService;
import com.kangye.enterprise.frontdesk.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @program: enterprise
 * @description: 轮播图接口
 * @author: 索腾龙
 * @create: 2021-05-27 15:31
 **/
@RestController
@CrossOrigin
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private BannerService bannerService;
    @Autowired
    private CircularController circularController;
    @Autowired
    HttpServletRequest request; //通过注解获取一个request

    //首页“搜索框”（李易衡）
//    @RequestMapping("/searchBoxItem")
//    public ViewJsonObject<Map<String,Object>> searchBoxItem(String sear){
//        return bannerService.searchBoxItem(sear);
//    }


    //首页“轮播图”（李易衡）
    @RequestMapping("/CarouselMap")
    public ViewJsonObject<Map<String,Object>> carouselMap(String regionName){
        return bannerService.carouselMap(regionName);
    }

    //首页“广告”（李易衡）
    @RequestMapping("/adver")
    public ViewJsonObject<Map<String,Object>> adver(String regionName){
        return bannerService.adver(regionName);
    }

    //首页“看通知、读政策、阅公示”最热（李易衡）
    @RequestMapping("/lookNoticeHot")
    public ViewJsonObject<Map<String,Object>> loookNoticeHot(String sear , Integer circularSynthesis, String regionName, String domoinName, String departmentName, String rankName) {
        return bannerService.lookNoticeHot(sear , circularSynthesis,regionName,domoinName,departmentName,rankName);
    }

    //首页“看通知、读政策、阅公示”最新（李易衡）
    @RequestMapping("/lookNoticeNew")
    public ViewJsonObject<Map<String,Object>> loookNoticeNew(String sear , Integer circularSynthesis, String regionName, String domoinName, String departmentName, String rankName) {
        return bannerService.lookNoticeNew(sear,circularSynthesis,regionName,domoinName,departmentName,rankName);
    }

    //首页“看通知”下的通知详情（李易衡）
//    @RequestMapping("/lookNoticeDetails")
//    public ViewJsonObject<Map<String,Object>> lookNoticeDetails(){
//        return bannerService.lookNoticeDetails();
//    }
//
//    //首页“读政策”（李易衡）
//    @RequestMapping("/readPolicy")
//    public ViewJsonObject<Map<String,Object>> readPolicy(String regionName,String domoinName,String departmentName,String rankName){
//        return bannerService.readPolicy(regionName,domoinName,departmentName,rankName);
//    }

    //首页“读政策“下的政策详情（李易衡）
    @RequestMapping("/readPolicyDetails")
    public List<Circular> readPolicyDetails(){
        return bannerService.readPolicyDetails();
    }

    //首页“报项目”（李易衡）
    @RequestMapping("/reportItemsHot")
    public ViewJsonObject<Map<String,Object>> reportItemsHot(String sear , Integer itemObj , String regionName, String domoinName, String departmentName) {
        return bannerService.reportItemsHot(sear,itemObj ,regionName,domoinName,departmentName);
    }

//    //首页“报项目”下的项目详情（李易衡）
//    @RequestMapping("/reportItemsDetails")
//    public ViewJsonObject<Map<String,Object>> reportItemsDetails(){
//        return bannerService.reportItemsDetails();
//    }

    //首页“阅公示”（李易衡）
//    @RequestMapping("/readPublicize")
//    public List<Publicity> readPubilcize(String regionName){
//        return bannerService.readPubilcize(regionName);
//    }
    //首页“精准配”（李易衡）
//    @RequestMapping("/preciseMatching")
//    public List<>


    //领域下拉框（李易衡）
    @RequestMapping("/domoinBox")
    public ViewJsonObject<Domoin> domoinBox(){
        return bannerService.domoinBox();
    }
    //部门下拉框（李易衡）
    @RequestMapping("/fieldBox")
    public ViewJsonObject<Department> departmentBox(){
        return bannerService.departmentBox();
    }
    //级别下拉框（李易衡）
    @RequestMapping("/rankBox")
    public ViewJsonObject<Rank> rankBox(){
        return bannerService.rankBox();
    }

    //精准配根据企业名查询企业地址（李易衡）
    @RequestMapping("/searchMatches")
    public ViewJsonObject<Map<String,Object>> searchMatches(String matchingCompanyname) {
        return bannerService.searchMatches(matchingCompanyname);
    }
    //精准配根据地址查询相似的政策（李易衡）
    @RequestMapping("/searchMatch")
    public ViewJsonObject<Map<String, Object>> searchMatch(String regionName){
        return bannerService.searchMatch(regionName);
    }
    //即将截止（李易衡）
    @RequestMapping("/searchMatchEnd")
    public ViewJsonObject<Map<String,Object>> searchMatchEnd(String regionName){
        return bannerService.searchMatchEnd(regionName);
    }
    //最高补贴

    //精准配筛选→政策主题（李易衡）
    @RequestMapping("/polithems")
    public ViewJsonObject<Polithem> polithems(){
        return bannerService.polithems();
    }

    //精准配筛选→产业领域（李易衡）
    @RequestMapping("/indufie")
    public ViewJsonObject<Domoin> indufie(){
        return bannerService.indufie();
    }

    //筛选政策主题（李易衡）
    @RequestMapping(value = "/subjectAreas",method = RequestMethod.POST)
    public ViewJsonObject<Map<String,Object>> subjectAreas(String regionName, String subjectAreasbox){
        List<String> subjectAreasboxlist = new ArrayList<>();
        String[] string = subjectAreasbox.split(",");
        for (String str:string) {
            subjectAreasboxlist.add(str);
            System.out.println(subjectAreasboxlist);
        }
        return bannerService.subjectAreasess(regionName,subjectAreasboxlist);
    }



    //筛选政策产业领域（李易衡）
    @RequestMapping(value = "/induld",method = RequestMethod.POST)
    public ViewJsonObject<Map<String,Object>> induld(String regionName, String induldbox){
        List<String> induldboxlist = new ArrayList<>();
        String[] string = induldbox.split(",");
        for (String str:string) {
            induldboxlist.add(str);
            System.out.println(induldboxlist);
        }
        return bannerService.induld(regionName,induldboxlist);
    }







//推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐推荐
    //主题设置→政策主题（李易衡）
    @RequestMapping("/follow")
    public void follow(Integer usersid,String thesetName){
        bannerService.follow(usersid,thesetName);
    }


    //取消关注（李易衡）
    @RequestMapping("cancelAtten")
    public void cancelAtten(Integer usersid,String thesetName){
        bannerService.cancelAtten(usersid,thesetName);
    }
//    @RequestMapping("/screenpol")
//    public String screenpol(String thesetUsersid,String thesetName){
//        String [] usersId = thesetUsersid.split(",");
//        String [] thesetname = thesetName.split(",");
//        List<Theset> list = new ArrayList<>();
//        for (int i = 0;i<usersId.length;i++){
//            Theset theset = new Theset();
//            theset.setThesetUsersid(Integer.valueOf(usersId[i]));
//            theset.setThesetName(thesetname[i]);
//            list.add(theset);
//        }
//        Integer code = bannerService.screnpol(list);
//        if (code>0){
//            return "200";
//        }else {
//            return "201";
//        }
//        //return bannerService.screenpol(screenpolicylist);
//    }
    //主题设置→政策主题→取消关注
//    @RequestMapping("/cancelAttention")
//    public String cancelAttention(Integer )



    //自定义
//    @RequestMapping("/custom")
//    public void custom(String polithemThemes){
//        bannerService.custom(polithemThemes);
//    }

    //从缓存中获取id（李易衡）
    @RequestMapping("/regionalizaUsers")
    public Integer regionalizaUsers(){
        Users users = (Users) request.getSession().getAttribute("users");
        Integer usersId = users.getUsersId();
        return usersId;
    }
    //项目定时推送里的区划设置（李易衡）
    @RequestMapping("/regionaliza")
    public String regionaliza(String alizationUsersid,String alizationRegionname){
//        Users users = (Users) request.getSession().getAttribute("users");
//        Integer usersId = users.getUsersId();
        String [] usersId = alizationUsersid.split(",");
        String [] regionName = alizationRegionname.split(",");
        List<Alization> list = new ArrayList<>();
        for (int i = 0;i<usersId.length;i++){
            Alization alization = new Alization();
            alization.setAlizationUsersid(Integer.valueOf(usersId[i]));
            alization.setAlizationRegionname(regionName[i]);
            list.add(alization);
        }
        Integer code = bannerService.regionaliza(list);
        if (code>0){
            return "200";
        }else {
            return "201";
        }

//        String[] regionalizationlist = regionalization.split(",");
//
//        //String[] usersIdlist = usersId.toString().split(",");
//        List<Alization> list= new ArrayList<>();
//        for (int i = 0;i<regionalization.length();i++){
//            String[] usersIdlist = new String[i+1];
//            usersIdlist = usersId.toString().split(",");
//            usersIdlist[i] = usersId.toString();
//            System.out.println(usersIdlist[i]);
//            Alization alization = new Alization();
//            alization.setAlizationUsersid(Integer.valueOf(usersIdlist[i]));
//            alization.setAlizationRegionname(regionalizationlist[i]);
//            list.add(alization);
//        }
//        Integer code = bannerService.regionaliza(list);
//        if (code>0){
//            return "200";
//        }else {
//            return "201";
//        }
//        for (String str:strings){
//            regionalizationlist.add(str);
//        }
//        return bannerService.regionaliza(regionalization,usersId);
    }






    //我的关注（李易衡）
    //专题
    //政策
    @RequestMapping("/dispol")
    public ViewJsonObject<Map<String,Object>>dispol(Integer gzcircularRolees,String usersId){
        return bannerService.dispol(gzcircularRolees,usersId);
    }
    //删除关注（李易衡）
    @RequestMapping("/deldispol")
    public String deldispol(String gzcircularId){

        String [] gzcircularIdd = gzcircularId.split(",");
        List<Gzcircular> list = new ArrayList<>();
        for (int i = 0;i<gzcircularIdd.length;i++){
            Gzcircular gzcircular = new Gzcircular();
            gzcircular.setGzcircularId(Integer.valueOf(gzcircularIdd[i]));
            list.add(gzcircular);
        }
        Integer code = bannerService.deldispol(list);
        if (code>0){
            return "200";
        }else {
            return "201";
        }
        //bannerService.deldispol(gzcircularRolees,usersId,gzcircularId);
    }


    //通知
    //点击帮助与反馈（李易衡）
    @RequestMapping("/fixedquan")
    public ViewJsonObject<Map<String,Object>> fixedquan(String question){
        return bannerService.fixedquan(question);
    }
    //我要反馈（李易衡）
    @RequestMapping("/feedback")
    public void feedback(Integer usersId,String helpfeedbackQuestion,String helpfeedbackEnclosure){
        bannerService.feedback(usersId,helpfeedbackQuestion,helpfeedbackEnclosure);
    }
    //是否解决（李易衡）
    @RequestMapping("/modifyState")
    public void modifyState(Integer usersId,String helpfeedbackQuestion){
        bannerService.modifyState(usersId,helpfeedbackQuestion);
    }
    //待解决问题展示（李易衡）
    @RequestMapping("/resolved")
    public ViewJsonObject<Map<String,Object>>resolved(Integer usersId){
        return bannerService.resolved(usersId);
    }
    //已解决问题展示（李易衡）
    @RequestMapping("/resolv")
    public ViewJsonObject<Map<String,Object>>resolv(Integer usersId){
        return bannerService.resolv(usersId);
    }
    //问题详情（李易衡）
    @RequestMapping("/quedetails")
    public ViewJsonObject<Map<String,Object>>quedetails(String helpfeedbackQuestion,Integer usersId){
        return bannerService.quedetails(helpfeedbackQuestion,usersId);
    }



    //我的消息（李易衡）
    @RequestMapping("/myNews")
    public ViewJsonObject<Map<String,Object>>myNews(Integer usersId){
        return bannerService.myNews(usersId);
    }

    //注册用户名查重
    @RequestMapping("/checking")
    public ViewJsonObject<Map<String,Object>> checking(String userUsername){
        return bannerService.checking(userUsername);
//        Integer code = bannerService.checking(userUsername);
//        if (code>0){
//            return 200;
//        }else {
//            return 201;
//        }
    }

//注册
    @RequestMapping(value = "/registerUser",method = RequestMethod.POST)
    public ViewJsonObject registerUser(Users user){
        return bannerService.registerUser(user);
    }

    //头条
    @RequestMapping("/head")
    public ViewJsonObject<Map<String,Object>> head(){
        return bannerService.head();
    }

}